<?php
namespace App\Models\Account;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Request;

// 玩家 根据游戏角色  新增 流失用户统计 只与昨日对比
class DeincStModel extends  Model{

	protected $table='online_time';
	public function paginate()
    {
    	$perPage = Request::get('per_page', 20);

        $page = Request::get('page', 1);

        $start = ($page-1)*$perPage;

        $tableAccount = 'new_user_login';
        $data = \DB::connection($this->selectdb())->table($tableAccount)->skip($page* $perPage)->take($perPage)->get();
        $data = $data->toArray();

        $total = \DB::connection($this->selectdb())->table($tableAccount)->count();

        // $data = json_decode($data, true);

        $list = static::hydrate($data);

        $paginator = new LengthAwarePaginator($list, $total, $perPage);

        $paginator->setPath(url()->current());

        return $paginator;
    }

    public static function with($relations)
    {
        return new static;
    }

    public function selectdb($select = ''){
        if ($select) {
            return $this->_db_select = $select;
        }
        return $this->_db_select;
    }

    //public function getConnectionName(){
    //    return $this->selectdb();
    //}
    public function getTable($table = ''){
    
        if ($table) {

            $this->table = $table;
        }

        return $this->table;
    }

}
